<?php

// shorturl redirects for artist detail pages like "2012.elevate.at/metallica"
function setShorturlRedirects() {
    $mysqli = new mysqli('localhost', "web14u2", "7K9f3Hn1", "web14db2");
    $mysqli->query("SET NAMES 'utf8'");

    // ARTISTS
    $query = "select url_shortcode, cat_type, event_year from view_artist_light";

    $results = $mysqli->query($query);

    $result_array = array();
    while($result = $results->fetch_assoc()) {
        array_push($result_array, $result);
    }
    $results->close();

    $shorturl_array = array();

    foreach($result_array as $result) {
        //$shorturl = $result["event_year"].".elevate.at/".$result["url_shortcode"]."/"; // does not work anymory
        $shorturl  = $result["url_shortcode"]."/";

        if(preg_match("#discourse#", $result["cat_type"])) {
            $normalurl = 'http://'.$result["event_year"].".elevate.at/diskurs/guest/".$result["url_shortcode"]."/";
        } else {
            $normalurl = 'http://'.$result["event_year"].".elevate.at/art/artist/".$result["url_shortcode"]."/";
        }

        $shorturl_array[$shorturl] = $normalurl;
    }

    // EVENTS
    $query = "select event_url_shortcode, typoid from view_event_light";

    $results = $mysqli->query($query);

    $result_array = array();
    while($result = $results->fetch_assoc()) {
        array_push($result_array, $result);
    }
    $results->close();

    foreach($result_array as $result) {
        $shorturl  = $result["event_url_shortcode"]."/";
        $normalurl = "index.php?id=".$result["typoid"]."/";

        $shorturl_array[$shorturl] = $normalurl;
    }

    return $shorturl_array;
}

$TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT']['redirects'] = setShorturlRedirects();


// UserFunc for discourse or art detail-view condition
function user_artistGetParam() {
    if(isset($_GET["tx_gkeisview_pi1"])) {
        $eisview_params = $_GET["tx_gkeisview_pi1"];

        if(isset($eisview_params["artist"]) || isset($eisview_params["guest"])) {
            return TRUE;
        }
    }

    return TRUE;
}


// Realrl Conf
$TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT']['preVars']['postVarSets']['_DEFAULT'] = array(
    'artist'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[artist]',
        ),
    ),
    'guest'            => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[guest]',
        ),
    ),

    'guest_name'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[guest_name]',
        ),
    ),
    'artist_name'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[artist_name]',
        ),
    ),
    'guests_per_page'  => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[guests_per_page]',
        ),
    ),
    'artists_per_page' => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[artists_per_page]',
        ),
    ),
    'artist_year' => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[artist_year]',
        ),
    ),
    'category_0'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][0]',
        ),
    ),
    'category_1'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][1]',
        ),
    ),
    'category_2'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][2]',
        ),
    ),
    'category_3'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][3]',
        ),
    ),
    'category_4'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][4]',
        ),
    ),
    'category_5'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][5]',
        ),
    ),
    'category_6'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][6]',
        ),
    ),
    'category_7'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][7]',
        ),
    ),
    'category_8'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][8]',
        ),
    ),
    'category_9'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][9]',
        ),
    ),
    'category_10'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][10]',
        ),
    ),
    'category_11'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][11]',
        ),
    ),
    'category_12'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][12]',
        ),
    ),
    'category_13'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][13]',
        ),
    ),
    'category_14'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[category][14]',
        ),
    ),
    'location_0'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][0]',
        ),
    ),
    'location_1'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][1]',
        ),
    ),
    'location_2'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][2]',
        ),
    ),
    'location_3'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][3]',
        ),
    ),
    'location_4'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][4]',
        ),
    ),
    'location_5'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][5]',
        ),
    ),
    'location_6'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][6]',
        ),
    ),
    'location_7'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][7]',
        ),
    ),
    'location_8'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][8]',
        ),
    ),
    'location_9'       => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][9]',
        ),
    ),
    'location_10'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][10]',
        ),
    ),
    'location_11'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][11]',
        ),
    ),
    'location_12'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][12]',
        ),
    ),
    'location_13'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][13]',
        ),
    ),
    'location_14'      => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[location][14]',
        ),
    ),
    'date_0'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][0]',
        ),
    ),
    'date_1'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][1]',
        ),
    ),
    'date_2'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][2]',
        ),
    ),
    'date_3'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][3]',
        ),
    ),
    'date_4'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][4]',
        ),
    ),
    'date_5'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][5]',
        ),
    ),
    'date_6'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][6]',
        ),
    ),
    'date_7'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][7]',
        ),
    ),
    'date_8'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][8]',
        ),
    ),
    'date_9'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][9]',
        ),
    ),
    'date_10'          => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][10]',
        ),
    ),
    'date_11'          => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][11]',
        ),
    ),
    'date_12'          => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][12]',
        ),
    ),
    'date_13'          => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][13]',
        ),
    ),
    'date_14'          => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[date][14]',
        ),
    ),
    'search'           => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[search]',
        ),
    ),
    'page'             => array(
        array(
            'GETvar' => 'tx_gkeisview_pi1[page]',
        ),
    ),
)
?>